#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n;
string s, t;
int a[26];
int f[26], ind[26];
void init() { rep(i, 0, 25) a[i] = -1, f[i] = i, ind[i] = 0; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return;
  f[fy] = fx;
}
int topo() {
  int group_cnt = 0;
  rep(i, 0, 25) if (f[i] == i) group_cnt++;
  stack<int> st;
  set<int> rt;
  rep(i, 0, 25) if (!ind[i]) st.push(i);
  while (st.size()) {
    int u = st.top();
    st.pop();
    rt.insert(find(u));
    int v = a[u];
    if (v != -1) {
      ind[v]--;
      if (!ind[v]) st.push(v);
    }
  }
  return group_cnt - rt.size();
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> s >> t;
  if (s == t) {
    cout << 0;
    return 0;
  }
  init();
  rep(i, 0, n - 1) {
    int x = s[i] - 'a';
    int y = t[i] - 'a';
    if (a[x] != -1 && a[x] != y) {
      cout << -1;
      return 0;
    }
    a[x] = y;
    ind[y] = 1;
  }
  int idle_cnt = 0, edge_cnt = 0;
  rep(i, 0, 25) {
    if (a[i] != -1 && a[i] != i) edge_cnt++, merge(a[i], i);
    if (ind[i] == 0) idle_cnt++;
  }
  if (!idle_cnt) {
    cout << -1;
    return 0;
  }
  rep(i, 0, 25) ind[i] = 0;
  rep(i, 0, 25) if (a[i] != i) ind[a[i]]++;
  int cycle_cnt = topo();
  cout << edge_cnt + cycle_cnt;
  return 0;
}